package com.mano.mall.service.strategy;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class StrategyFactory {

	private static Map<String, PayStrategy> strategyBean = new ConcurrentHashMap<String, PayStrategy>();

	/**
	 * 使用Java反射机制初始化类
	 * 
	 * @param classAddres
	 * @return
	 */
	public static PayStrategy getPayStrategy(String classAddres) {
		try {
			PayStrategy beanPayStrategy = strategyBean.get(classAddres);
			if (beanPayStrategy != null) {
				return beanPayStrategy;
			}
			Class<?> forName = Class.forName(classAddres);
			PayStrategy payStrategy = (PayStrategy) forName.newInstance();
			strategyBean.put(classAddres, payStrategy);
			return payStrategy;
		} catch (Exception e) {
			return null;
		}

	}
}
